<?php

namespace App\Admin\Controllers;

use App\Models\Decode;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class DecodeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '影视解析';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Decode());

        $grid->column('id', __('Id'));
        $grid->column('name', __('解析名称'));
        $grid->column('param', __('解析参数'));
        $grid->column('url', __('解析地址'));
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));
        $states = [
            'on'  => ['value' => 1, 'text' => '开启', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '关闭', 'color' => 'warning'],
        ];
        $grid->column('isdelete', __('状态'))->switch($states);

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Decode::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('解析名称'));
        $show->field('param', __('解析参数'));
        $show->field('url', __('解析地址'))->link();
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('修改时间'));
        $show->field('isdelete', __('状态'))->using([0=>"冻结",1=>"正常"]);

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Decode());

        $form->text('name', __('解析名称'));
        $form->text('param', __('解析参数'));
        $form->url('url', __('解析地址'));
        $form->switch('isdelete', __('状态'))->default(1);

        return $form;
    }
}
